package com.heima.artical.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.artical.service.ArticleService;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping
public class ArticleController {
    @Autowired
    ArticleService articleService;

    @GetMapping("/api/v1/author/findByUserId/{id}")
    public ResponseResult<ApAuthor> findByUserId(@PathVariable("id") Integer id) {
        ApAuthor one = articleService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getUserId, id));
        return ResponseResult.okResult(one);
    }

    @PostMapping("/api/v1/author/save")
    public ResponseResult save(@RequestBody ApAuthor apAuthor) {
        articleService.save(apAuthor);
        return ResponseResult.okResult();
    }

}
